Inf
Table of Contents
Introduction #
Inf is a brief script designed to simplify the process of creating and opening a new file using the CLI in popular IDEs like VSCode, IntelliJ, Sublime Text, and more.
When working on a project, the task of creating and opening a file can be a bit tedious. That’s why I developed this script, to bring you a more convenient experience.
Almost all IDEs provide a CLI tool for creating a new file, but when I try to make and open a new one, it only works if the file or directory already exists.
With Inf, you can create and open a new file smoothly even if the file or directory does not exist! 🚀
Supported IDEs and Editors #
IDEs and editors that I tested by myself are as follows:
- JetBrains (IntelliJ, WebStorm, PyCharm, etc.)
- Visual Studio Code
- Sublime Text
Code Snippet #
It only accepts the IDEs installed in “/usr/local/bin”. ⚠️
#!/bin/bash
# Instruction: This script is used to open a file or directory in the specified IDE.
# It will create the file or directory if it doesn't exist.
# Usage: inf <ide> "<file>" | inf <ide> "<directory>" | inf <ide>
# Example: inf idea "src/main/java/com/example/MyClass.java" | inf code "src/main/java/com/example" | inf idea
# Declare the first argument as the IDE.
IDE=$1
# Declare the second argument as the target file or directory.
TARGET=$2
# Check if the target IDE is valid.
## Currently, we accept IDE installed in "/usr/local/bin" only!
if [ ! -x "/usr/local/bin/$IDE" ]; then
echo "$IDE - IDE could not be found"
exit 1
fi
# Check if the target file or directory is invalid.
## If the target is empty, open the IDE in the current directory.
if [ -z "$TARGET" ]; then
"$(command -v $IDE)" "./"
exit 0
fi
# Get the directory name to create the file in.
dir=$(dirname -- "$TARGET")
# If the directory doesn't exist, make it.
if [ ! -d "$dir" ]; then
mkdir -p "$dir"
fi
# If the file doesn't exist, create it.
if [ ! -f "$TARGET" ]; then
touch "$TARGET"
fi
# Open the file in the specified IDE.
"$(command -v $IDE)" "$TARGET"
Installation #
Before installing it, please check that the ‘inf’ command already exists in your system.
$ command -v inf || echo "Not exist"
# if the 'inf' command doesn't exist, you can install it.
$ git clone
$ cd inf
$ sudo chmod 755 inf.sh
$ sudo cp inf.sh /usr/local/bin/inf
Usage #
You don’t need double quotation marks for the file or directory path if no special character exists.
However, double quotation marks must be used if the path contains special characters. 🥸
# default usage
$ inf [ide] "[file]" | [directory]
$ inf idea "src/main/java/com/example/MyClass.java"
# Also you can use the alias in your shell configuration file. (e.g. .bashrc, .zshrc)
$ alias infi="inf idea"
$ alias infc="inf code"
$ alias infs="inf subl"
$ infi "src/main/java/com/example/MyClass.java"
Conclusion #
I hope this script will help you create a new file more conveniently. 👋
If you have any questions or suggestions, please feel free to contact me.
Thank you for reading! 🙏